home *** CD-ROM | disk | FTP | other *** search
- 10 ! ******************************************************************
- 20 ! Example: STRIPCHART (Counter States)
- 30 !
- 40 ! This program demonstrates stripchart operation. It generates
- 50 ! a PANEL and places a STRIPCHART in it. The STRIPCHART widget
- 60 ! then displays the timing states of a 7-bit digital counter.
- 70 !
- 80 ! *******************************************************************
- 90 !
- 100 ! Define colors and array of colors
- 110 !
- 120 INTEGER Black,White,Red,Yellow,Green,Cyan,Blue,Magenta,Colors(1:7)
- 130 DATA 0,1,2,3,4,5,6,7
- 140 READ Black,White,Red,Yellow,Green,Cyan,Blue,Magenta
- 150 Colors(1)=White
- 160 Colors(2)=Red
- 170 Colors(3)=Yellow
- 180 Colors(4)=Blue
- 190 Colors(5)=Cyan
- 200 Colors(6)=Green
- 210 Colors(7)=Magenta
- 220 !
- 230 ! Other variables:
- 240 !
- 250 ! Display(*): Used to get display dimensions
- 260 ! B(*),C(*),D(*),Ctr,Bitstr$: Used to implement 7-bit counter
- 270 ! Total: Cumulative count of 7-bit counter
- 280 ! N: Useful counter
- 290 ! Bitstr$: Gets binary digits
- 300 !
- 310 INTEGER Display(1:4),B(1:7),C(1:7),D(1:7),Ctr,N,Dw,Dh,W,H,X,Y
- 320 DIM Bitstr$[32]
- 330 REAL Total
- 340 !
- 350 GESCAPE CRT,3;Display(*)
- 360 Dw=Display(3)-Display(1)
- 370 Dh=Display(4)-Display(2)
- 380 CLEAR SCREEN
- 390 !
- 400 W=Dw
- 410 H=Dh
- 420 X=0
- 430 Y=0
- 440 GOSUB Buildstrip
- 450 !
- 460 ! Get ready for main loop. The B(*) and D(*) arrays are used
- 470 ! to translate the counter count to trace Y coordinates. The Ctr
- 480 ! variable handles the count and the Total keeps a running tally.
- 490 !
- 500 DATA 1,3,5,7,9,11,13,0,0
- 510 READ B(*),Ctr,Total
- 520 MAT D=B
- 530 !
- 540 ! Set up Quit event, turn on PANEL
- 550 !
- 560 ON EVENT @Strip,"SYSTEM MENU" GOTO Finis
- 570 CONTROL @Strip;SET ("VISIBLE":1)
- 580 !
- 590 ! Loop and update traces
- 600 !
- 610 LOOP
- 620 GOSUB Gettrace
- 630 END LOOP
- 640 STOP
- 650 !
- 660 ! *********** End of Main Program ******************
- 670 !
- 680 Gettrace:!
- 690 !
- 700 ! The Gettrace routine handles the update of the traces on the display.
- 710 ! To begin, take the current counter value and use it to update the trace.
- 720 ! The traces are drawn from one Y value to another:
- 730 !
- 740 ! Bit 0: 0 is Y=1 1 is Y=2
- 750 ! Bit 1: 0 is Y=3 1 is Y=4
- 760 ! Bit 2: 0 is Y=5 1 is Y=6
- 770 ! Bit 3: 0 is Y=7 1 is Y=8
- 780 ! Bit 4: 0 is Y=9 1 is Y=10
- 790 ! Bit 5: 0 is Y=11 1 is Y=12
- 800 ! Bit 6: 0 is Y=13 1 is Y=14
- 810 !
- 820 ! The B(*) array is effectively simply a set of constants that contains
- 830 ! the Y-values that correspond to a 0 value for each trace. The C(*)
- 840 ! array is generated using the B(*) array and the counter value to give
- 850 ! the Y-values for the actual current count.
- 860 !
- 870 ! To create the C(*) array from the count, the count is converted
- 880 ! into a string using IVAL that gives the counter value in binary
- 890 ! (that is, a counter value of 13 gives a string "0000000000001101").
- 900 !
- 910 ! Then, the string is scanned from right to left (which scans through
- 920 ! the count from Bit 0 to Bit 6), and the character "0" or "1" is converted
- 930 ! to its numeric equivalent. The result is added to the value in B(*)
- 940 ! for the corresponding bit to load into C(*) for the corresponding bit.
- 950 !
- 960 ! The D(*) array keeps the value from the previous ON CYCLE event.
- 970 ! This is done because when you make a transition from a 0 to a 1
- 980 ! on a trace you have to plot the old Y value and new Y value at
- 990 ! the same X value. If you had instead just plotted each new value
- 1000 ! with each ON CYCLE event, the trace transitions would be plotted as
- 1010 ! angles with the traces rising and falling between subsequent X values.
- 1020 !
- 1030 Bitstr$=IVAL$(Ctr,2)
- 1040 L=LEN(Bitstr$)
- 1050 FOR N=1 TO 7
- 1060 C(N)=B(N)+VAL(Bitstr$[L-(N-1);1])
- 1070 NEXT N
- 1080 !
- 1090 ! Draw the traces -- set X location and then plot the previous trace
- 1100 ! values followed by the current trace values.
- 1110 !
- 1120 CONTROL @Strip;SET ("POINT LOCATION":Total)
- 1130 CONTROL @Strip;SET ("VALUES":D(*),"VALUES":C(*))
- 1140 !
- 1150 ! Save the current trace values, and modulo update the 7-bit counter.
- 1160 !
- 1170 MAT D=C
- 1180 Ctr=(Ctr+1) MOD 128
- 1190 !
- 1200 ! Increment the running total. If numeric overflow, reset STRIPCHART
- 1210 ! and start over again. To do this, you black out all the traces,
- 1220 ! change the X origin back to 0, draw the traces back to the origin
- 1230 ! while they are black (so they will be invisible against the black
- 1240 ! background), and then set the colors again.
- 1250 !
- 1260 Total=Total+1
- 1270 IF Total=32767 THEN
- 1280 Total=0
- 1290 ASSIGN @Strip TO *
- 1300 GOSUB Buildstrip
- 1310 END IF
- 1320 RETURN
- 1330 !
- 1340 ! *************** Build Stripchart ************************
- 1350 !
- 1360 Buildstrip:!
- 1370 !
- 1380 ! Set up main STRIPCHART parameters -- 7 traces, and scroll 1/40th at
- 1390 ! a time since the traces are 40 units long.
- 1400 !
- 1410 ASSIGN @Strip TO WIDGET "STRIPCHART";SET ("VISIBLE":0)
- 1420 CONTROL @Strip;SET ("TITLE":"Example: STRIPCHART (Counter States)")
- 1430 CONTROL @Strip;SET ("X":50,"Y":25,"WIDTH":.75*W,"HEIGHT":.75*H)
- 1440 CONTROL @Strip;SET ("TRACE BACKGROUND":Black)
- 1450 CONTROL @Strip;SET ("TRACE COUNT":7,"MINIMUM SCROLL":1/40)
- 1460 !
- 1470 ! Set up X-axis parameters -- initial origin (before scrolling) of 1,
- 1480 ! trace display width of 40, keep numbering on and set it to 5 digits.
- 1490 !
- 1500 CONTROL @Strip;SET ("CURRENT AXIS":"X","ORIGIN":0,"RANGE":40)
- 1510 CONTROL @Strip;SET ("NUMBER FORMAT":"FIXED","DIGITS":5)
- 1520 !
- 1530 ! Set up Y-axis parameters -- enough range for 7 traces, turn off
- 1540 ! numbering.
- 1550 !
- 1560 CONTROL @Strip;SET ("CURRENT AXIS":"Y")
- 1570 CONTROL @Strip;SET ("ORIGIN":0,"RANGE":15,"SHOW NUMBERING":0)
- 1580 !
- 1590 ! Set up seven traces -- different color and label for each. (The
- 1600 ! first 8 traces actually have distinctive colors, but they are set
- 1610 ! to show how to do it.)
- 1620 !
- 1630 FOR N=1 TO 7
- 1640 CONTROL @Strip;SET ("CURRENT TRACE":N,"TRACE PEN":Colors(N))
- 1650 CONTROL @Strip;SET ("TRACE LABEL":"BIT "&VAL$(N-1))
- 1660 NEXT N
- 1670 !
- 1680 CONTROL @Strip;SET ("MAXIMIZABLE":0,"RESIZABLE":0)
- 1690 CONTROL @Strip;SET ("SYSTEM MENU":"Quit","VISIBLE":1)
- 1700 RETURN
- 1710 !
- 1720 ! ******************** Go Here on Exit ************************
- 1730 !
- 1740 ! The ON CYCLE is disabled before destroying the STRIPCHART.
- 1750 ! Otherwise, it might call the handler and cause an error, since the
- 1760 ! handler does not have any widgets remaining.
- 1770 !
- 1780 Finis:!
- 1790 OFF CYCLE ! Stop ON CYCLE *FIRST!*
- 1800 ASSIGN @Strip TO *! Delete STRIPCHART widget
- 1810 END
-